package com.ai.demo.service;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.util.MimeTypeUtils;

import java.awt.*;

@Service
public class MultimodalityServer {

    @Autowired
    private OpenAiChatModel baseChatModel;

    @Autowired
    private OpenAiApi baseOpenAiApi;

    public String describeImageContent() {
        OpenAiChatModel openAiChatModel = baseChatModel.mutate()
                .openAiApi(baseOpenAiApi)
                .defaultOptions(OpenAiChatOptions.builder().model("deepseek-chat").temperature(0.7).build())
                .build();
        return ChatClient.create(openAiChatModel).prompt().advisors(new SimpleLoggerAdvisor())
                .user(u -> u.text("解释一下你在这张图片上看到了什么?")
                        .media(MimeTypeUtils.IMAGE_PNG, new ClassPathResource("\\20250703152705.png")))
                .call()
                .content();
    }
}
